<template>
  <j-modal
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    :title="title"
    :visible="visible"
    :width="1200"
    switchFullscreen
    @cancel="handleCancel"
    @ok="handleOk"
  >
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form">
        <a-row>
          <h2>选择企业</h2>
        </a-row>
        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select
                placeholder="请选择企业"
                show-search
                option-filter-prop="children"
                :filter-option="filterOption"
              >
                <a-select-option value="all" @click="select('all')">
                  Web端企业校验
                </a-select-option>
                <a-select-option
                  v-for="(value) in options"
                  :key="value.enterpriseId"
                  :value="value.enterpriseId"
                  @click="select(value.enterpriseId)"
                >{{ value.enterpriseName }}
                </a-select-option>
              </a-select>

<!--              <j-dict-select-tag v-model="cjmodel.cllx" dictCode="car_cllx" placeholder="车辆类型"/>-->
<!--&lt;!&ndash;              原有的搜索车辆类型&ndash;&gt;-->
<!--              <j-search-select-tag-->
<!--                v-model="cjmodel.cllx"-->
<!--                :dictOptions="cllxList"-->
<!--                placeholder="请选择车辆类型"-->
<!--              >-->
<!--              </j-search-select-tag>-->

            </a-form-item>
          </a-col>
        </a-row>

        <a-checkbox-group v-model="listOrder" @change="onChangeOrder">
          <a-row>
            <h2>上传订单信息</h2>
          </a-row>
          <a-row>
            <a-col :span="8">
              <a-checkbox value="orderNumber">订单号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="epositAmount">订/定金金额，可为:0</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="epositreceivedAmount">订/定实收金额</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="quoteAmount">订单总价</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="depositAttribute">订/定金性质(1:可退、2:不可退、3:有条件可退)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="depositContent">定金描述备注(1:有固化条款，系统对接；2:如果没有，自行录入。)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="depositNotes">定金不可退条件(订/定金性质:不可退,本字段必填)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="orderDate">订单生成时间</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="enterpriseName">企业名称</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="region">销售区域</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="enterpriseId">社会信用统一代码</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="businessAddress">销售地址</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesCode">销售顾问工号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesName">销售顾问姓名</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesPhone">销售顾问电话</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="ownerName">订购方姓名</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="documentType">证件类型</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="documentNumber">订购方证件号码</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="ownerPhone">订购方电话</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carBrand">汽车品牌(例子：宝马)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carModel">汽车车型(公告或3C产品认证型号)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carType">车辆类型(1:传统车、2:新能源汽车)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carTypeConfiguration">车型配置：(例子：X12021款sDrive20Li时尚型)新增</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="fuelType">汽车燃料类型(1:油/电、2:电、3:油)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carVin">VIN码</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carColor">外饰颜色</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="interiorColor">内饰颜色</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="isNewCar">是否为新车(默认值：是)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="engineNumber">发动机号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="qualifiedNumber">合格证号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="batteryNumber">动力蓄电池组编号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="importProveNumber">货物进口证明书号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="importEngineNumber">进口机动车辆随车检验单号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesStatus">销售状态</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="netsign">是否可网签</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="renetsign">重签状态</a-checkbox>
            </a-col>
          </a-row>
        </a-checkbox-group>
        <a-checkbox-group v-model="listContract" @change="onChangeContract">
          <a-row>
            <h2>上传合同信息</h2>
          </a-row>
          <a-row>
            <a-col :span="8">
              <a-checkbox value="orderNumber">订单号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="contractNo">合同编号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="sellingType">合同类型(1:个人零售、2:批售)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="contractSignIime">合同签订时间（改合同完成时间）</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="enterpriseName">企业名称</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="region">销售区域</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="enterpriseId">社会信用统一代码</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="businessAddress">销售地址</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesCode">销售顾问工号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesName">销售顾问姓名</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesPhone">销售顾问电话</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="buyerName">购买方姓名</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="buyerType">购买方性质</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="buyerPhone">购买方手机号码</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="pinType">证件类型</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="pinNumber">证件号码</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carBrand">汽车品牌 (例子：宝马)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carModel">汽车车型(公告或3C产品认证型号)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carType">车辆类型(1:传统车、2:新能源汽车)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carTypeConfiguration">车型配置:(例子:X12021款 sDrive20Li 时尚型)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="fuelType">汽车燃料类型(1:油/电、2:电、3:油)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carVin">车架号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="engineNumber">发动机号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="batteryInvoiceNumber">电池发票号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="batteryInvoiceTime">电池发票时间</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carColor">外饰颜色</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="interiorColor">内饰颜色</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="qualifiedNumber">合格证号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="batteryNumber">动力蓄电池组编号(车辆类型:新能源汽车,本字段必填)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="importProveNumber">货物进口证明书号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="importEngineNumber">进口机动车辆随车检验单号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="chargeCondition">充电条件落实方式(1:自建、2:专用、3:公用)(车辆类型:新能源汽车,本字段必填)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="finalPrice">总价</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="paytype">付款类型(1:按揭、2:一次性付款)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="paymentMethodJson">支付方式(1:刷卡、2:转账、3:支票、4:现金、5:微信、6:支付宝)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="receivableamount">总应收</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="receivedamount">总实收</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="invoiceTime">开票日期</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="invoiceCode">发票代码</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="invoiceNumber">发票号码</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="excludingTaxPrice">不含税价</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="invoicePrice">价税合计</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="deliveryMethod">交付方式(1:自提、2:委托)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="deliveryAddr">预计交车地点</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="deliveryTime">预计交车时间</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="agentOrNot">是否代办项目(1:是、2:否)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="agentContentsJson">代办项目内容 如选是：必填</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesStatus">销售状态</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="netsign">是否可网签</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="renetsign">重签状态</a-checkbox>
            </a-col>
          </a-row>
        </a-checkbox-group>
        <a-checkbox-group v-model="listDeliver" @change="onChangeDeliver">
          <a-row>
            <h2>上传交付信息</h2>
          </a-row>
          <a-row>
            <a-col :span="8">
              <a-checkbox value="carVin">车架号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="engineNumber">发动机号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="batteryNumber">动力蓄电池组编号(车辆类型:新能源汽车,本字段必填)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carBrandNumber">品牌及规格型号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="carColor">外饰颜色</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="interiorColor">内饰颜色</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="orderNumber">订单号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="contractNo">合同编号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="deliveryAddr">交车地点</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="deliveryTime">交车时间</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="enterpriseName">企业名称</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesCode">交付专员工号</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesName">交付专员姓名</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesPhone">交付专员电话</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="buyerName">接收方姓名</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="buyerPhone">接收方电话</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="pinType">证件类型</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="pinNumber">证件号码</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="deliverContents">交车清单内容</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="accessoriesContents">随车附件(文本格式)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="accessoriesContentsPic1">随车附件1(照片base64格式)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="accessoriesContentsPic2">随车附件2(照片base64格式)</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="salesStatus">销售状态</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="netsign">是否可网签</a-checkbox>
            </a-col>
            <a-col :span="8">
              <a-checkbox value="renetsign">重签状态</a-checkbox>
            </a-col>
          </a-row>
        </a-checkbox-group>

      </a-form>
    </a-spin>
    <a-button type="primary" @click="updateParams">修改</a-button>
  </j-modal>
</template>

<script>
import { getAction, httpAction } from '@/api/manage'

export default {
  name: 'CxmFieldVerificationModal',
  data() {
    return {
      title: '字段校验',
      visible: false,

      model: {},
      options: [],
      listOrder: [],
      valueOrder: '',
      listContract: [],
      valueContract: '',
      listDeliver: [],
      valueDeliver: '',
      enterpriseId: '',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },

      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        add: '/cxm/cxmOrderManager/add',
        edit: '/cxm/cxmOrderManager/edit',
        getEnterpriseNameAndId: '/cxm/cxmEnterprise/getEnterpriseNameAndId',
        getParamsById: '/cxm/cxmParamCheckConfig/getParamsById',
        addParams: '/cxm/cxmParamCheckConfig/addParams',
        updateParams: '/cxm/cxmParamCheckConfig/updateParams'
      },
      showDing: false
    }
  },
  created() {
  },
  methods: {
    select(value) {
      console.log(value)
      let httpurl = this.url.getParamsById
      let params = value
      this.enterpriseId = value
      getAction(httpurl, { id: params, type: '0' }).then((res) => {
        if (res.success) {
          console.log(res.result)
          this.valueOrder = res.result.join(',')
          this.listOrder = res.result
          console.log(this.valueOrder)
        }
      })
      getAction(httpurl, { id: params, type: '1' }).then((res) => {
        if (res.success) {
          console.log(res.result)
          this.valueContract = res.result.join(',')
          this.listContract = res.result
          console.log(this.valueContract)
        }
      })
      getAction(httpurl, { id: params, type: '2' }).then((res) => {
        if (res.success) {
          console.log(res.result)
          this.valueDeliver = res.result.join(',')
          this.listDeliver = res.result
          console.log(this.valueDeliver)
        }
      })

    },
    add() {
      let httpurl = this.url.getEnterpriseNameAndId
      getAction(httpurl).then((res) => {
        if (res.success) {
          console.log(res.result)
          this.edit(res.result)
        } else {
          this.edit([])
        }
      })
    },
    edit(record) {
      this.form.resetFields()
      this.options = record
      this.visible = true

    },
    close() {
      this.$emit('close')
      this.visible = false
    },

    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      );
    },

    handleOk() {
      const that = this
      let httpurl = this.url.addParams
      httpAction(httpurl, {
        params: this.valueOrder,
        businessType: '0',
        enterpriseUscc: this.enterpriseId
      }, 'post').then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
        } else {
          that.$message.warning(res.message)
        }
      })
        .finally(() => {
          that.confirmLoading = false
          that.close()
        })
      httpAction(httpurl, {
        params: this.valueContract,
        businessType: '1',
        enterpriseUscc: this.enterpriseId
      }, 'post').then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
        } else {
          that.$message.warning(res.message)
        }
      })
        .finally(() => {
          that.confirmLoading = false
          that.close()
        })
      httpAction(httpurl, {
        params: this.valueDeliver,
        businessType: '2',
        enterpriseUscc: this.enterpriseId
      }, 'post').then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
        } else {
          that.$message.warning(res.message)
        }
      })
        .finally(() => {
          that.confirmLoading = false
          that.close()
        })
    },
    updateParams() {
      const that = this
      let httpurl = this.url.updateParams
      httpAction(httpurl, {
        params: this.valueOrder,
        businessType: '0',
        enterpriseUscc: this.enterpriseId
      }, 'post').then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
        } else {
          that.$message.warning(res.message)
        }
      })
        .finally(() => {
          that.confirmLoading = false
          that.close()
        })
      httpAction(httpurl, {
        params: this.valueContract,
        businessType: '1',
        enterpriseUscc: this.enterpriseId
      }, 'post').then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
        } else {
          that.$message.warning(res.message)
        }
      })
        .finally(() => {
          that.confirmLoading = false
          that.close()
        })
      httpAction(httpurl, {
        params: this.valueDeliver,
        businessType: '2',
        enterpriseUscc: this.enterpriseId
      }, 'post').then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
        } else {
          that.$message.warning(res.message)
        }
      })
        .finally(() => {
          that.confirmLoading = false
          that.close()
        })
    },
    handleCancel() {
      this.close()
    },
    onChangeOrder(value) {
      console.log(value)
      this.valueOrder = value.join(',')
      console.log(this.valueOrder)
    },
    onChangeContract(value) {
      this.valueContract = value.join(',')
    },
    onChangeDeliver(value) {
      this.valueDeliver = value.join(',')
    }
  }
}
</script>

<style lang="less" scoped>
</style>